package com.slipper.system.log.controller;

import com.slipper.util.Tool;
import jakarta.annotation.Resource;

import com.slipper.constants.Constants;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.slipper.system.log.bo.LoginLogBO;
import com.slipper.system.log.service.LoginLogService;
import com.slipper.util.ResultUtil;

/**
 * 用户登录日志表
 */
@RestController
@RequestMapping("/system/loginLog")
public class LoginLogController {
    @Resource
    private LoginLogService loginLogService;

    @PostMapping(value = "/queryBy")
    public String queryBy(@RequestBody LoginLogBO bo) {
        if(Tool.isBlank(bo.getId())) {
            return ResultUtil.failureResult("数据获取失败！");
        }
        return ResultUtil.successResult(loginLogService.queryBy(bo.getId()));
    }

    @PostMapping(value = "/queryMonthStatList")
    public String queryMonthStatList() {
        return ResultUtil.successResult(loginLogService.queryMonthStatList());
    }

    @PostMapping(value = "/queryPage")
    public String queryPage(@RequestBody LoginLogBO bo) {
        //管理员查询所有
        if (!Constants.getCurrentUser().isSuperAdmin()) {
            bo.setOrgId(Constants.getCurrentUser().getOrgId());
        }
        return ResultUtil.successResult(loginLogService.queryPage(bo));
    }

    @PostMapping(value = "/save")
    public String save(@RequestBody LoginLogBO bo) {
        return ResultUtil.saveResult(loginLogService.save(bo));
    }

    @PostMapping(value = "/delete")
    public String delete(@RequestBody LoginLogBO bo) {
        return ResultUtil.deleteResult(loginLogService.delete(bo));
    }
}
